package com.mall.biz.trade.impl.o2o;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.biz.trade.O2OTradeBiz;
import com.mall.biz.trade.impl.o2o.incluce.BalanceTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.EshopTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.MaiDanTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.MinSuTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.TuanGouTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.WeiShangTradeImpl;
import com.mall.biz.trade.impl.o2o.incluce.ZhiHuiTradeImpl;
import com.mall.constant.TradeTypeConstant;
import com.mall.dto.TradePriceAndBuyCountDTO;
import com.mall.pojo.Trade;

/**
 * 020业务的工厂方法
 * 
 * @author Administrator
 *
 */
@Service
public class O2OTradeFactoryImpl{

	@Autowired
	private MaiDanTradeImpl maiDanTradeImpl;
	@Autowired
	private MinSuTradeImpl minSuTradeImpl;
	@Autowired
	private TuanGouTradeImpl tuanGouTradeImpl;
	@Autowired
	private ZhiHuiTradeImpl zhiHuiTradeImpl;
	@Autowired
	private WeiShangTradeImpl weiShangTradeImpl;
	@Autowired
	private EshopTradeImpl eshopTradeImpl;
	@Autowired
	private BalanceTradeImpl balanceTradeImpl;
	/**
	 * 返回具体的操作实体
	 * 
	 * @param type
	 * @return
	 */
	private O2OTradeBiz factoryTypeTradeBiz(Integer type) {
		if (type == TradeTypeConstant.TYPE_MAIDAN) {/* 买单 */
			return maiDanTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_TUANGOU) {/* 团购 */
			return tuanGouTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_MINSU) {/* 民宿 */
			return minSuTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_ZHIHUI) {/* 智慧餐厅 */
			return zhiHuiTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_WEISHANG) {/* 微商 */
			return weiShangTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_HANDRECHARGE) {/* 买个店手动充值 */
			return eshopTradeImpl;
		}
		if (type == TradeTypeConstant.TYPE_BALANCEPAY) {/* 买个店手动充值 */
			return balanceTradeImpl;
		}
		
		return null;
	}

	public TradePriceAndBuyCountDTO pack4PirceAndBuyCount(HttpServletRequest request, Integer type, Long price,
			Integer buyCount, Long parentId) {
		return factoryTypeTradeBiz(type).pack4PirceAndBuyCount(request, type, price, buyCount, parentId);
	}

	public Boolean beforeInsert(HttpServletRequest request, Trade trade) {
		return factoryTypeTradeBiz(trade.getType()).beforeInsert(request, trade);
	}

	public Boolean afterSuccInsert(HttpServletRequest request, Trade trade) {
		return factoryTypeTradeBiz(trade.getType()).afterSuccInsert(request, trade);
	}

	public Boolean afterErrorInsert(HttpServletRequest request, Trade trade) {
		return factoryTypeTradeBiz(trade.getType()).afterErrorInsert(request, trade);
	}

}
